﻿using System;

namespace Borg.AddOn
{
    [Serializable]
    internal sealed class ComposerApiHookChain : IComposerApiHook
    {
        private readonly IComposerApiHook[] _hooks;

        public ComposerApiHookChain(IComposerApiHook[] hooks)
        {
            _hooks = hooks;
        }

        public void OnCompositionOperation(PlugCompositionOperation operation, Slot slot, Plug plug)
        {
            foreach (IComposerApiHook hook in _hooks)
                hook.OnCompositionOperation(operation, slot, plug);
        }

        public void OnCompositionOperation(TagCompositionOperation operation, Slot slot, Plug plug, string tagName)
        {
            foreach (IComposerApiHook hook in _hooks)
                hook.OnCompositionOperation(operation, slot, plug, tagName);
        }

        public void OnExtensionOperation(ExtensionOperation operation, Extension extension)
        {
            foreach (IComposerApiHook hook in _hooks)
                hook.OnExtensionOperation(operation, extension);
        }

        public void OnExtensionTypeOperation(ExtensionTypeOperation operation, ExtensionType extensionType)
        {
            foreach (IComposerApiHook hook in _hooks)
                hook.OnExtensionTypeOperation(operation, extensionType);
        }

        public void OnPlugOperation(PlugOperation operation, Plug plug)
        {
            foreach (IComposerApiHook hook in _hooks)
                hook.OnPlugOperation(operation, plug);
        }

        public void OnSetProperty(ComposerOperation operation)
        {
            foreach (IComposerApiHook hook in _hooks)
                hook.OnSetProperty(operation);
        }

        public void OnSlotOperation(SlotOperation operation, Slot slot)
        {
            foreach (IComposerApiHook hook in _hooks)
                hook.OnSlotOperation(operation, slot);
        }
    }
}
